/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastraFuncionario.java
 *
 * Created on 29/03/2012, 01:47:04
 */

package tela;

import bd.Consultas;
import java.awt.Color;
import java.util.List;
import java.util.Vector;
import tabela.Funcionario;

/**
 *
 * @author Edu
 */
public class CadastraBuscaFuncionario extends javax.swing.JPanel {

    /** Creates new form CadastraFuncionario */
    
    private int idFuncionarioSelecionado = 999999;
    private int ERRO = 0;
    private int SUCESSO = 1;
    private int INFO = 2;
    
    
    public CadastraBuscaFuncionario() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jTextFieldLoginFuncionario = new javax.swing.JTextField();
        jTextFieldEnderecoFuncionario = new javax.swing.JTextField();
        jTextFieldCodigoFuncionario = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNomeFuncionario = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jFormattedTextFieldCpfFunc = new javax.swing.JFormattedTextField();
        jFormattedTextFieldRGFunc = new javax.swing.JFormattedTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldEmailFunc = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldTelFunc = new javax.swing.JTextField();
        jButtonSalvarFuncionario = new javax.swing.JButton();
        jButtonExcluirFuncionario = new javax.swing.JButton();
        jButtonNovoCliente = new javax.swing.JButton();
        jTextFieldSenhaFuncionario = new javax.swing.JPasswordField();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldConfirmacaoSenhaFuncionario = new javax.swing.JPasswordField();
        jPanel5 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldBuscafuncionario = new javax.swing.JTextField();
        jButtonBuscarfuncionario = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jListFuncionarios = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        mensagens = new javax.swing.JTextArea();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/figura/seta.png"))); // NOI18N
        jLabel13.setMinimumSize(new java.awt.Dimension(10, 256));

        jLabel14.setBackground(new java.awt.Color(255, 255, 255));
        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel14.setText("Cliente");

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 2, true), "", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 3, 14), java.awt.Color.gray)); // NOI18N

        jTextFieldLoginFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jTextFieldEnderecoFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jTextFieldCodigoFuncionario.setEditable(false);
        jTextFieldCodigoFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Endereço:");

        jTextFieldNomeFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel6.setText("Usuário:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Código:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel7.setText("Senha:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Nome:");

        try {
            jFormattedTextFieldCpfFunc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            jFormattedTextFieldRGFunc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###-#")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldRGFunc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldRGFuncActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel10.setText("CPF:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel11.setText("R.G.:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel8.setText("E-Mail:");

        jTextFieldEmailFunc.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel9.setText("Telefone:");

        jTextFieldTelFunc.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jButtonSalvarFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonSalvarFuncionario.setText("Salvar");
        jButtonSalvarFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalvarFuncionarioActionPerformed(evt);
            }
        });

        jButtonExcluirFuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonExcluirFuncionario.setText("Excluir");
        jButtonExcluirFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirFuncionarioActionPerformed(evt);
            }
        });

        jButtonNovoCliente.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonNovoCliente.setText("Novo Funcionário");
        jButtonNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNovoClienteActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel17.setText("Confirmação de senha:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButtonNovoCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonExcluirFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSalvarFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCodigoFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel10)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldNomeFuncionario)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jFormattedTextFieldCpfFunc, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormattedTextFieldRGFunc, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldEnderecoFuncionario)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jTextFieldTelFunc, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel8)
                                .addGap(8, 8, 8)
                                .addComponent(jTextFieldEmailFunc, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextFieldLoginFuncionario)
                                    .addComponent(jTextFieldSenhaFuncionario))
                                .addGap(18, 18, 18)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldConfirmacaoSenhaFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCodigoFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNomeFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jFormattedTextFieldCpfFunc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jFormattedTextFieldRGFunc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldEnderecoFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldEmailFunc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldTelFunc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldLoginFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldSenhaFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldConfirmacaoSenhaFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSalvarFuncionario)
                    .addComponent(jButtonExcluirFuncionario)
                    .addComponent(jButtonNovoCliente))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 2, true), "", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 3, 14), java.awt.Color.gray)); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel12.setText("Nome");

        jTextFieldBuscafuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jButtonBuscarfuncionario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButtonBuscarfuncionario.setText("Buscar");
        jButtonBuscarfuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarfuncionarioActionPerformed(evt);
            }
        });

        jListFuncionarios.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jListFuncionarios.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jListFuncionarios.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListFuncionariosValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(jListFuncionarios);

        mensagens.setBackground(new java.awt.Color(204, 204, 204));
        mensagens.setColumns(20);
        mensagens.setEditable(false);
        mensagens.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        mensagens.setForeground(new java.awt.Color(204, 0, 0));
        mensagens.setRows(5);
        mensagens.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jScrollPane4.setViewportView(mensagens);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldBuscafuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonBuscarfuncionario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane4))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldBuscafuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonBuscarfuncionario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/figura/seta.png"))); // NOI18N
        jLabel15.setMinimumSize(new java.awt.Dimension(10, 256));

        jLabel16.setBackground(new java.awt.Color(255, 255, 255));
        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel16.setText("Funcionário");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 97, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(41, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jFormattedTextFieldRGFuncActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldRGFuncActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jFormattedTextFieldRGFuncActionPerformed

    private void jButtonExcluirFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirFuncionarioActionPerformed
        
        String sql = "from Funcionario where cpfFuncionario='" + jFormattedTextFieldCpfFunc.getText()+"'";
        Funcionario funcionario = (Funcionario) Consultas.getUmaLinha(sql);
        if(funcionario != null) {
                if (Consultas.removeDoBanco(funcionario)) {
                    limpaComponentes();
                    jButtonBuscarfuncionarioActionPerformed(null);
                    mensagem("Funcionário excluído com sucesso!", SUCESSO);
                } else {
                    mensagem("Erro ao excluir funcionario!", ERRO);
                }
        } else {
                mensagem("Erro ao excluir funcionario!", ERRO);
            }       
       
    }//GEN-LAST:event_jButtonExcluirFuncionarioActionPerformed

    private void jButtonNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNovoClienteActionPerformed
        idFuncionarioSelecionado = 999999;
        limpaComponentes();
        jListFuncionarios.clearSelection();
        mensagem("Preencha os dados do Funcionário", INFO);        
    }//GEN-LAST:event_jButtonNovoClienteActionPerformed

    private void jButtonSalvarFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarFuncionarioActionPerformed
        if(verificaCamposEmBranco()) { 
            
            return;
        }
        int idFuncionario = idFuncionarioSelecionado;
         if (idFuncionarioSelecionado == 999999) {
        if(verificaSeCPFJaExiste(jFormattedTextFieldCpfFunc.getText())) {            
            mensagem("CPF já existente", ERRO);
            return;
        }
        if(verificaSeUsuarioJaExiste(jTextFieldLoginFuncionario.getText())) {            
            mensagem("Usuário já existente", ERRO);
            return;
        }        
        
        idFuncionario = getIdDisponivel();
        
         } 
         
        
       Funcionario funcionario = new Funcionario(idFuncionario);      
       funcionario.setNomeFuncionario(jTextFieldNomeFuncionario.getText());
       funcionario.setCpfFuncionario(jFormattedTextFieldCpfFunc.getText());
       funcionario.setRgFuncionario(jFormattedTextFieldRGFunc.getText());
       funcionario.setEmailFuncionario(jTextFieldEmailFunc.getText());
       funcionario.setEnderecoFuncionario(jTextFieldEnderecoFuncionario.getText());
       funcionario.setSenha(jTextFieldSenhaFuncionario.getText());
       funcionario.setUsuario(jTextFieldLoginFuncionario.getText());
       funcionario.setTelefoneFuncionario(jTextFieldTelFunc.getText());
       
          if (Consultas.salvaNoBanco(funcionario)) {
            idFuncionarioSelecionado = idFuncionario;       
            //jButtonBuscarClienteActionPerformed(null);
            String mensagem = "Cliente salvo com sucesso!";
            mensagem(mensagem, SUCESSO);
            String sql = "from Funcionario where upper(nomeFuncionario) like upper('%" + jTextFieldBuscafuncionario.getText() + "%')";
            preencheListaBusca(Consultas.getListObjetos(sql));
            //JOptionPane.showMessageDialog(null, "Cliente salvo com sucesso", "Salvar", JOptionPane.INFORMATION_MESSAGE);
        } else {
            String mensagem = "Erro ao salvar cliente!";
            mensagem(mensagem, ERRO);
            //JOptionPane.showMessageDialog(null, "Erro ao salvar cliente", "Erro", JOptionPane.ERROR);
        }
    }//GEN-LAST:event_jButtonSalvarFuncionarioActionPerformed

    private void jListFuncionariosValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListFuncionariosValueChanged
        
         if (jListFuncionarios.getSelectedValue() == null) {
            return;
        }
        limpaComponentes();
        System.out.println("Selecionado=" + jListFuncionarios.getSelectedValue());
        String sql = "from Funcionario where nomeFuncionario='" + jListFuncionarios.getSelectedValue().toString()+"'";
        List resultList = Consultas.getListObjetos(sql);
        for (Object o : resultList) {
            Funcionario funcionario = (Funcionario) o;
            idFuncionarioSelecionado = funcionario.getIdFuncionario();
            jTextFieldNomeFuncionario.setText(funcionario.getNomeFuncionario());
            jFormattedTextFieldCpfFunc.setText(funcionario.getCpfFuncionario());
            jFormattedTextFieldRGFunc.setText(funcionario.getRgFuncionario());
            jTextFieldEmailFunc.setText(funcionario.getEmailFuncionario());
            jTextFieldEnderecoFuncionario.setText(funcionario.getEnderecoFuncionario());
            jTextFieldSenhaFuncionario.setText(funcionario.getSenha());
            jTextFieldLoginFuncionario.setText(funcionario.getUsuario()); 
            jTextFieldTelFunc.setText(funcionario.getTelefoneFuncionario()); 
            jTextFieldCodigoFuncionario.setText(Integer.toString(funcionario.getIdFuncionario()));
        }
    }//GEN-LAST:event_jListFuncionariosValueChanged

    private void jButtonBuscarfuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarfuncionarioActionPerformed
         String sql = "from Funcionario where upper(nomeFuncionario) like upper('%" + jTextFieldBuscafuncionario.getText() + "%')";
        preencheListaBusca(Consultas.getListObjetos(sql));
    }//GEN-LAST:event_jButtonBuscarfuncionarioActionPerformed

    public void limpaComponentes() {
        jTextFieldNomeFuncionario.setText("");
        jFormattedTextFieldCpfFunc.setText("");
        jFormattedTextFieldRGFunc.setText("");
        jTextFieldEmailFunc.setText("");
        jTextFieldEnderecoFuncionario.setText("");
        jTextFieldSenhaFuncionario.setText("");
        jTextFieldLoginFuncionario.setText("");    
        jTextFieldTelFunc.setText(""); 
        jTextFieldCodigoFuncionario.setText("");
       
   }
   private boolean verificaCamposEmBranco(){
       boolean erro = false;
       if(jTextFieldNomeFuncionario.getText().equals(""))
         erro = true;
       if(jFormattedTextFieldCpfFunc.getText().equals(""))
           erro = true;
       if(jFormattedTextFieldRGFunc.getText().equals(""))
           erro = true;
       if(jTextFieldEmailFunc.getText().equals(""))
           erro = true;
       if(jTextFieldEnderecoFuncionario.getText().equals(""))
           erro = true;
       if(jTextFieldSenhaFuncionario.getText().equals(""))
          erro = true;
       if(jTextFieldLoginFuncionario.getText().equals(""))
          erro = true;
       if(jTextFieldTelFunc.getText().equals(""))
          erro = true;
       
       
       if(!jTextFieldSenhaFuncionario.getText().equals(jTextFieldConfirmacaoSenhaFuncionario.getText())) {
           mensagem("Confirme corretamente a senha!", ERRO);
           return true;
       }
       
       if(erro) {
           mensagem("Campos inválidos!", ERRO);  
       }
       
       return erro;
   }
    private boolean verificaSeCPFJaExiste(String cpf) {
        boolean achou = false;
        int quantidade = Consultas.getCount("select count(*) from Funcionario where cpfFuncionario='"+cpf+"'");
        if(quantidade > 0) {
            return true;
        }
        return false;    
    }
    private boolean verificaSeUsuarioJaExiste(String usuario) {
        boolean achou = false;
        int quantidade = Consultas.getCount("select count(*) from Funcionario where usuario='"+usuario+"'");
        if(quantidade > 0) {
            return true;
        }
        return false;    
    }
      private int getIdDisponivel() {
        boolean achou = false;
        int quantidade = Consultas.getCount("select count(*) from Funcionario");
        int novoID = quantidade + 1;
        while (!achou) {
            int existeEsseId = Consultas.getCount("select count(idFuncionario) from Funcionario where idFuncionario =" + novoID);
            if (existeEsseId == 0) {
                return novoID;
            }
            novoID += 1;
        }
        return 0;
    }
      
    private void mensagem(String msg, int tipo) {
        if(tipo == 0) { //erro
            mensagens.setForeground(Color.RED);           
            mensagens.setText(msg);
        } else if(tipo == 1) { //sucesso
            mensagens.setForeground(Color.BLUE);           
            mensagens.setText(msg);
        } if(tipo == 2) { //info
            mensagens.setForeground(Color.black);           
            mensagens.setText(msg);
        }
    }
    private void preencheListaBusca(List resultList) {
        Vector tableData = new Vector();
        for (Object o : resultList) {
            Funcionario funcionario = (Funcionario) o;
            String nome = funcionario.getNomeFuncionario();   
            if(nome.equals("Administrador"))
                continue;
            tableData.add(nome);
            System.out.println(nome);
        }
        if (tableData.size() == 0) {
            tableData.add("Nenhuma ocorrência");
        }
        jListFuncionarios.setListData(tableData);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBuscarfuncionario;
    private javax.swing.JButton jButtonExcluirFuncionario;
    private javax.swing.JButton jButtonNovoCliente;
    private javax.swing.JButton jButtonSalvarFuncionario;
    private javax.swing.JFormattedTextField jFormattedTextFieldCpfFunc;
    private javax.swing.JFormattedTextField jFormattedTextFieldRGFunc;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jListFuncionarios;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField jTextFieldBuscafuncionario;
    private javax.swing.JTextField jTextFieldCodigoFuncionario;
    private javax.swing.JPasswordField jTextFieldConfirmacaoSenhaFuncionario;
    private javax.swing.JTextField jTextFieldEmailFunc;
    private javax.swing.JTextField jTextFieldEnderecoFuncionario;
    private javax.swing.JTextField jTextFieldLoginFuncionario;
    private javax.swing.JTextField jTextFieldNomeFuncionario;
    private javax.swing.JPasswordField jTextFieldSenhaFuncionario;
    private javax.swing.JTextField jTextFieldTelFunc;
    private javax.swing.JTextArea mensagens;
    // End of variables declaration//GEN-END:variables

}
